package cn.cvs.servlet.supplier;

import cn.cvs.pojo.Supplier;
import cn.cvs.service.SupplierService;
import cn.cvs.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "SuppilerToUpdateServlet", urlPatterns = "/sys/supplier/toUpdate")
public class SuppilerToUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        SupplierService supplierService = (SupplierService) SpringUtil.getBean ( "supplierService" );
        Integer id = Integer.valueOf ( request.getParameter ( "id" ) );
        Supplier supplierById = supplierService.getSupplierById ( id );
        request.setAttribute ( "supplier", supplierById );
        request.getRequestDispatcher ( "/WEB-INF/jsp/supplier/update.jsp" ).forward ( request,response );
    }
}
